package com.anycc.cloud.gateway.fallback;

import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;

/**
 * Core模块降级回调
 */
@Component
public class AnyccCoreFallbackProvider implements FallbackProvider {
    private static final String SERVICE_NAME = "anycc-core";
    private static final String SERVICE_DISABLE = "服务不可用";

    @Override
    public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
        return new AnyccFallbackResponse(cause, SERVICE_NAME, SERVICE_DISABLE);
    }

    /**
     * @return 需要针对此微服务做回退处理（该名称一定要是注册进入 eureka 微服务中的那个 serviceId 名称）；
     */
    @Override
    public String getRoute() {
        return SERVICE_NAME;
    }
}
